/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */

package org.ipig.constants;

/**
 * mongo持久层常量
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: MongoCnst.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public class MongoCnst {
    //业务模型
    public static final String MODEL = "model";
    //度量项集合
    public static final String METRICS = "metrics";
    public static final String DEFAULT_ID = "_id";
    public static final String TIME_UNIT = "timeUnit";





/*    public static final Integer SORT_ASC = 1;//DbmsOperators.SortType.ASC.num
    public static final Integer SORT_DESC = -1;//参考DbmsOperators.SortType.DESC.num
    public static final String TIME = FieldCnst.TIME;//参考FieldCnst
    public static final String CREATE_TIME = FieldCnst.CREATE_TIME;//参考FieldCnst
    public static final String MODIFY_TIME = FieldCnst.MODIFY_TIME;//参考FieldCnst
    public static final String VERSION = FieldCnst.VERSION;//参考FieldCnst*/

//    public static final String PROPS = FieldCnst.PROPS;//参考FieldCnst

    /**
     * TIME_LEVEL
     */
    public static final String TIME_LEVEL = "timeLevel";
    /**
     * PREFIX_MODEL
     ***/
    public static final String PREFIX_MODEL = MODEL + SymbolCnst.DOT;
    /**
     * PREFIX_METRICS
     ***/
    public static final String PREFIX_METRICS = METRICS + SymbolCnst.DOT;


    /**
     * 单个集合的存储信息
     */
    public enum CollStats {
        NS("ns", "域名空间，由数据库名和集合名构成"),
        COUNT("count", "集合中包含的文档数量"),
        AVG_OBJ_SIZE("avgObjSize", "集合中一个对象的平均大小"),
        STORAGE_SIZE("storageSize", "分配给集合存储所有文档的存储空间"),
        SIZE("size", "集合中所有记录的总大小");
        //code
        public final String code;
        //title
        public final String title;

        /**
         * @param code
         * @param title
         */
        private CollStats(String code, String title) {
            this.code = code;
            this.title = title;
        }
    }

    /**
     * 保存模式
     */
    public enum SaveMode {
        ACCUMULATE("accumulate", "累加模式"),
        REPLACE("replace", "替换模式");
        //code
        public final String code;
        //title
        public final String title;

        /**
         * @param code
         * @param title
         */
        private SaveMode(String code, String title) {
            this.code = code;
            this.title = title;
        }

        /**
         * parse
         *
         * @param code
         * @return
         */
        public static SaveMode parse(String code) {
            for (SaveMode mode : SaveMode.values()) {
                if (mode.code.equals(code)) {
                    return mode;
                }
            }
            return null;
        }
    }

    /**
     * 时间单元
     */
    public enum TimeUnit {
        YEAR_UNIT("yearUnit", "年"),
        MONTH_UNIT("monthUnit", "月"),
        DAY_UNIT("dayUnit", "天"),
        HOUR_UNIT("hourUnit", "时");
        //code
        public final String code;
        //title
        public final String title;

        /**
         * @param code
         * @param title
         */
        private TimeUnit(String code, String title) {
            this.code = code;
            this.title = title;
        }

        /**
         * parse
         *
         * @param code
         * @return
         */
        public static TimeUnit parse(String code) {
            for (TimeUnit timeLevel : TimeUnit.values()) {
                if (timeLevel.code.equals(code)) {
                    return timeLevel;
                }
            }
            return null;
        }
    }
}
